<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax登录页面</title>
    <script src="/static/js/jquery-1.12.4.min.js"></script>
    <script>
        $(function () {
            $('#btnLogin').click(function () {
                $.ajax({
                    'url': '/login_ajax_check',
                    'type': 'post',
                    'data': {'username': $('#username').val(), 'password': $('#password').val()},
                    'dataType': 'json'
                }).success(function (data) {
                    if (data.code == 1) {
                        location.href = '/index'
                    } else {
                        $('#erromessage').show().html('用户名或密码错误！')
                    }

                })
            })

        })
    </script>
    <style>
        #erromessage {
            display: none;
            color: red;
        }
    </style>
</head>
<body>
<div>
    用户名：<input type="text" id="username"><br/>
    密码：<input type="password" id="password"><br/>
    <input type="button" id="btnLogin" value="登录">
    <div id="erromessage"></div>
</div>
{{ msg }}
</body>
</html>